#common
export module=$(word 1,${MAKECMDGOALS})

#paths
export groupPath=${CURDIR}
export GOPATH=${groupPath}/z_gopath
export modulePath=${groupPath}/${module}

#global target
ifeq ($(findstring ${module},cleanall sync),${module})
cleanall:
	find ${GOPATH}/out -type f | xargs rm -f
sync:
	@cp -R ${CURDIR}/agent ~/apps/repx/stx/roles/go/tpls && \
	cp -R ${CURDIR}/cmd ~/apps/repx/stx/roles/go/tpls && \
	cp -R ${CURDIR}/pkg ~/apps/repx/stx/roles/go/tpls && \
	cp -R ${CURDIR}/go.mod ~/apps/repx/stx/roles/go/tpls
else

#load module file
mkfile=${modulePath}/Makefile.mk
include ${mkfile}

#module target and dependences
${module} : ${GOPATH}/out/${module} ${GOPATH}/bin/go-bindata
	@echo "use ${module} module"

#dependences
${GOPATH}/out/${module}:
	mkdir -p ${GOPATH}/out/${module}

${GOPATH}/bin/go-bindata:
	GOPATH=${GOPATH} GOPROXY=https://goproxy.cn go install github.com/jteeuwen/go-bindata/go-bindata
help: #helper
	@grep '^[^#[:space:]].*: ' ${mkfile} | awk -F'#'  {'print "--> "$$1  "#"$$2'}
endif